package com.example.demo3.demos.web;

import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;

@RestController
@RequestMapping("/request")
public class userController {
    @RequestMapping("/getHeader")
    public String getHeader(HttpServletRequest request){
        String userAgent=request.getHeader("User-Agent");
        return "useragent:"+userAgent;
    }
    @RequestMapping("/getHeader2")//用Spring
    public String getHeader2(@RequestHeader("User-Agent") String userAgent){
        return "userAgent:"+userAgent;
    }
}
